package com.googlecode.cardamomo.ermodel;

import java.util.Collection;
import java.util.Set;
import java.util.TreeSet;
import java.util.Vector;

import javax.xml.bind.annotation.*;

/**
 * Schema is just a collection of tables and views, so far
 * 
 * @author jtorne
 *
 */
@XmlType(namespace=DataType.CARDAMOMO_NAMESPACE)

public class Schema {

	private Vector<Table> tables = new Vector<Table>(); 
	
	private String name = null;
	
	public Schema()
	{
	}
	
	public Schema(String name)
	{
		setName(name);
	}

	@XmlAttribute(required=true)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public Collection<Table> getTables()
	{
		return tables;
	}

	public void setTables(Vector<Table> tables) {
		this.tables = tables;
	}

	public Set<String> getTableNames()
	{
		Set<String> tableSet = new TreeSet<String>();
		for (int i=0; i < tables.size(); i++) {
			tableSet.add(tables.get(i).getName());
		}
		return tableSet;
	}
	
	public boolean existsTable(String tableName) {
		for (int i=0; i < tables.size(); i++) {
			if (tables.get(i).getName().equals(tableName)) return true;
		}
		return false;
	}
	
	public int getTableCount()
	{
		return tables.size();
	}
	
	public Table getTable(String name)
	{
		for (int i=0; i < tables.size(); i++) {
			if (tables.get(i).getName().equals(name)) return tables.get(i);
		}
		return null;
	}
	
	public void addTable(Table tm)
	{
		tables.add(tm);
	}
}
